import type { QueryUser, User } from '@/types/User'

import http from './http'
import { env } from '@/utils/env'
import type { ResponeData } from '@/types/HttpType'
import type { PageData } from '@/types/PageData'

export const postUser = async (data: User): Promise<ResponeData<User>> => {

    return await http({
        url: env.VITE_HCFL_MRG + '/user/adder',
        method: 'post',
        data
    })

}

export const putUser = async (data: User): Promise<ResponeData<User>> => {

    return http({
        url: env.VITE_HCFL_MRG + '/user/updater',
        method: 'put',
        data
    })

}

export const getUserList = async (params: QueryUser): Promise<ResponeData<PageData<User>>> => {


    let res = await http<PageData<User>>({
        url: env.VITE_HCFL_MRG + '/user/list',
        method: 'get',
        params
    })

    return res;

}

export const getUserDetail = async (id: number): Promise<User> => {


    let res = await http<User>({
        url: env.VITE_HCFL_MRG + '/user/detail',
        method: 'get',
        params: { id }
    })
    return res.data

}

export const deleteUser = async (id: number): Promise<User> => {


    let res = await http<User>({
        url: env.VITE_HCFL_MRG + '/user/deleter/' + id,
        method: 'delete',
    })
    return res.data

}

export const resetPassword = async (data: {id:number, newPassword:string}) => {
  return await http({
        url: env.VITE_HCFL_MRG + '/user/password/reset',
        method: 'put',
        data
    })
}